//
//  AppDelegate.m
//  IntelligentHousehold
//
//  Created by wmwMAC on 17/6/16.
//  Copyright © 2017年 Cassie. All rights reserved.
//

#import "AppDelegate.h"

#import "MainViewController.h"
#import "LogInViewController.h"

#import "GuideViewController.h"//启动页
#import "IQKeyboardManager.h"

//1 改好 2待确认 3改好 4待确认 5改好 

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // 隐藏导航栏UINavigationBar黑线
    [[UINavigationBar appearance]  setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    //    [[UINavigationBar appearance] setClipsToBounds:YES];
    
    
    
    NSUserDefaults *useDef = [NSUserDefaults standardUserDefaults];
    // 使用 NSUserDefaults 读取用户数据
    if (![useDef boolForKey:@"notFirst"]) {
        // 如果是第一次进入引导页
        self.window.rootViewController = [[GuideViewController alloc] init];
    }else{
        // 否则直接进入应用
        [self setOtherViewController];
        
        // 启动图片延时: 1秒
        [NSThread sleepForTimeInterval:0.01];
        
        
        //设置键盘
        [self setUpKeyBoard];
        
        
    }
    
    
    
    
    
    
    return YES;
}
-(void)setOtherViewController{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    
    
    if (saveDic.count) {
        MainViewController *rootVC = [[MainViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:rootVC];
        self.window.rootViewController = nav;
        
    }else{
        LogInViewController *loginVC = [[LogInViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        self.window.rootViewController = nav;

    }
    
    
    
    
    
    
    [self.window makeKeyAndVisible];
}
//键盘设置
-(void)setUpKeyBoard {
    //键盘
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    manager.shouldResignOnTouchOutside = YES;
    manager.shouldToolbarUsesTextFieldTintColor = YES;
    manager.enableAutoToolbar = NO;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
